/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import Entity.ResourceInfoObject;
import Entity.ResourceTypeObject;

/**
 *
 * @author gauconpuka
 */
public class Resource_HiepLV {
public Connection GetConnection()
{
    Connection con = null;
        try {
            
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String url = "jdbc:odbc:connect";
            String user = "sa";
            String pass = "1234$";
            con = DriverManager.getConnection(url, user, pass);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Resource_HiepLV.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Resource_HiepLV.class.getName()).log(Level.SEVERE, null, ex);
        }
    return con;
}

public Iterator GetRasourceInfoOject(String rio,int page)
{
    Vector v = new Vector();
    int tong=0;
        try {
            
            String sql = "Select * from ResourceInfoTable";
            Connection mycon = GetConnection();
            Statement st = mycon.createStatement();
            ResultSet rs = st.executeQuery(sql);
            int Startpage=(page-1)*4+1;
            int Endpage=(page*4)+1;
            while(rs.next())
            {
                if(page>Startpage&&page<Endpage)
                {
                  ResourceInfoObject List=new ResourceInfoObject();
                  List.setResourceFolder(rs.getNString(1));
                  List.setResourceName(rs.getNString(2));
                  List.setResourceTypeID(rs.getInt(3));
                  List.setShareTypeID(rs.getInt(4));
                  v.addElement(List);
                  tong++;
                }
            }
          
        } catch (SQLException ex) {
            Logger.getLogger(Resource_HiepLV.class.getName()).log(Level.SEVERE, null, ex);
        }
          return v.iterator();
}

public Iterator GetRasourceTypeOject(String rto,int page)
{
    Vector v = new Vector();
    int tong=0;
        try {
            
            String sql = "Select * from ResourceTypeTable";
            Connection mycon = GetConnection();
            Statement st = mycon.createStatement();
            ResultSet rs = st.executeQuery(sql);
            int Startpage=(page-1)*4+1;
            int Endpage=(page*4)+1;
            while(rs.next())
            {
                if(page>Startpage&&page<Endpage)
                {
                  ResourceTypeObject List=new ResourceTypeObject();
                  List.setResourceExtender(rs.getString(1));
                  List.setResourceIcon(rs.getBytes(2));
                  List.setResourceTypeID(rs.getInt(3));
                  v.addElement(List);
                  tong++;
                }
            }
          
        } catch (SQLException ex) {
            Logger.getLogger(Resource_HiepLV.class.getName()).log(Level.SEVERE, null, ex);
        }
          return v.iterator();
}
}
